using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using it.mintlab.mobilenet.mintar.Properties;

namespace it.mintlab.mobilenet.mintar
{
    public class StarsPanel: Panel
    {
        private int rate = 0;
        private PictureBox star1;
        private PictureBox star2;
        private PictureBox star3;
        private PictureBox star4;
        private PictureBox star5;

        public int getRate()
        {
            return rate;
        }

        public void resetRate()
        {
            rate = 0;
            for (int i = 0; i <= 4; i++)
            {
                ((PictureBox)this.Controls[i]).Image = Resources.starUp;
            }
        }

        public StarsPanel():base()
        {
            star1 = new PictureBox();
            star2 = new PictureBox();
            star3 = new PictureBox();
            star4 = new PictureBox();
            star5 = new PictureBox();
            star1.Image = Resources.starUp;
            star2.Image = Resources.starUp;
            star3.Image = Resources.starUp;
            star4.Image = Resources.starUp;
            star5.Image = Resources.starUp;
            star1.Name = "pcBxStar1";
            star2.Name = "pcBxStar2";
            star3.Name = "pcBxStar3";
            star4.Name = "pcBxStar4";
            star5.Name = "pcBxStar5";
            star1.Click += new EventHandler(starClick);
            star2.Click += new EventHandler(starClick);
            star3.Click += new EventHandler(starClick);
            star4.Click += new EventHandler(starClick);
            star5.Click += new EventHandler(starClick);
            star1.Size = new System.Drawing.Size(20, 20);
            star2.Size = new System.Drawing.Size(20, 20);
            star3.Size = new System.Drawing.Size(20, 20);
            star4.Size = new System.Drawing.Size(20, 20);
            star5.Size = new System.Drawing.Size(20, 20);
            star1.Location = new System.Drawing.Point(0, 0);
            star2.Location = new System.Drawing.Point(20, 0);
            star3.Location = new System.Drawing.Point(40, 0);
            star4.Location = new System.Drawing.Point(60, 0);
            star5.Location = new System.Drawing.Point(80, 0);
            this.Controls.Add(star1);
            this.Controls.Add(star2);
            this.Controls.Add(star3);
            this.Controls.Add(star4);
            this.Controls.Add(star5);
            this.Height = 20;
            this.Width = 100;
        }

        private void starClick(object sender, EventArgs e)
        {
            string senderName = ((PictureBox)sender).Name;
            int starId = int.Parse(senderName.Substring(senderName.Length-1));
            rate = starId;
            for (int i = 0; i <= 4; i++)
            {
                if (i < starId)
                    ((PictureBox)this.Controls[i]).Image = Resources.starDown;
                else
                    ((PictureBox)this.Controls[i]).Image = Resources.starUp;
            }
        }

    }
}
